package pers.wk.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;
import pers.wk.producer.MessageSender;
import pers.wk.protocol.Response;

/**
 * 发送消息
 */
@RestController
@RequestMapping(value = "/msg/")
public class ProducerController {

    @Autowired
    private MessageSender messageSender;

    /**
     * 发送站内信
     *
     * @param message
     */
    @PostMapping(value = "sendZnx")
    public Response<String> sendZnx(@Value(value = "${msg.znx.exchange}") String exchange,
                                    @Value(value = "${msg.znx.binding-key}") String routingKey,
                                    @RequestParam(value = "message") String message) {
        messageSender.convertAndSend(message, exchange, routingKey);
        return Response.ok("请求成功");
    }

    /**
     * 发送公众号微信通知
     *
     * @param exchange
     * @param routingKey
     * @param message
     * @return
     */
    @PostMapping(value = "sendWeChat")
    public Response<String> sendWeChat(@Value(value = "${msg.wechat.exchange}") String exchange,
                                       @Value(value = "${msg.wechat.binding-key}") String routingKey,
                                       @RequestParam(value = "message") String message) {
        messageSender.convertAndSend(message, exchange, routingKey);
        return Response.ok("请求成功");
    }

}
